<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class UserDonate extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'user_donate';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_text',
        'is_ship_text',
        'freight_type_text'
    ];
    

    
    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2'), '-1' => __('Status -1'), '-2' => __('Status -2'),'-3' => __('Status -3')];
    }

    public function getIsShipList()
    {
        return ['0' => __('Is_ship 0'), '1' => __('Is_ship 1')];
    }

    public function getFreightTypeList()
    {
        return ['0' => __('Freight_type 0'), '1' => __('Freight_type 1')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsShipTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_ship']) ? $data['is_ship'] : '');
        $list = $this->getIsShipList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getFreightTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['freight_type']) ? $data['freight_type'] : '');
        $list = $this->getFreightTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function user()
    {
        return $this->belongsTo('User', 'uid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function userid()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function shopapply()
    {
        return $this->belongsTo('ShopApply', 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
